import java.util.ArrayList;
import controlP5.ControlP5;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PImage;

//File for all static global variables
//Specifically, for the processing PApplet object
//-------------------------------------------------
public class GLOBAL {
	//The processing applications
	//Call when you need to use processing functions like color()
	//		ex: GLOBAL.processing.color();
	public static PApplet processing;
	
	//ControlP5 for GUI
    public static ControlP5 controlP5;
	
    //FONTS
    public static PFont fontSegoe;
    public static PFont fontSmall;
    
	//COLORS
    public static int colorBackground;
    public static int colorMenu;
    public static int colorTabSelected;
    public static int colorTabDeselected;
    public static int colorTabMouseOver;
    public static int colorListBox;
    public static int colorEllipse;
    public static int colorEllipseHighlight;
    public static int colorBarHighlight;
    public static int colorFemale;
    public static int colorMale;
    public static int colorCountry;
    
    //Starting RGB for gradients
    private static int g1_r = 170;
    private static int g1_g = 230;
    private static int g1_b = 140;
    private static int g2_r = 170;
    private static int g2_g = 140;
    private static int g2_b = 230;
    private static boolean gradientOne = false;	//true when using gradient 1, false when using gradient 2
    private static int adjust = 0;	//amount to adjust green and blue values of gradient
    
    //List of Artists to Ignore (when Filtering)
    public static ArrayList<ArtistData> IGNORE;
	
    //Age range (as currently selected by user)
    public static int AGE_MIN = 13;
    public static int AGE_MAX = 65;
    
    //Current sex selection
    //	= 0		Male & Female
    //	= 1		Females
    //  = 2		Males
    public static int SEX = 0;
    
    //Current Tab Selected
    //	= 0		Top Artists
    //	= 1		Heat Calendar
    //	= 2		Ignored Artists
    public static int TAB = 0;
    
    //Current Country Selected
    public static String COUNTRY = "All";
    
    //Current number of views being displayed on screen
    public static int VIEW_COUNT = 0;
    public static int HEATVIEW_COUNT = 0;
    
    //Filters user is displaying
    //	(Currently 2 Max)
    //		IDEA: If we want to add Filter History, we can turn this into a list.
    public static int FILTER1;
    public static int FILTER2;

    //List of Countries
    public static ArrayList<String> ALL_COUNTRIES;
	
	//Y-Value directly in-between two Views on screen 
	public static int ViewMidline = 400;
	
	//LastFM API Object
	public static LastfmAPI LAST_FM;
	
	//Images
	public static PImage HUE;
	
	//String Arrays for heat maps
	public static String[] heatRow2005;
	public static String[] heatRow2006;
	public static String[] heatRow2007;
	public static String[] heatRow2008;
	public static String[] heatRow2009;
    
    //---------------------------------------------------------------------------
    //		M E T H O D S
    //---------------------------------------------------------------------------
    
	public GLOBAL(PApplet p) {
		processing = p;
		controlP5 = new ControlP5(processing);
        controlP5.setMoveable(false);
        controlP5.setAutoDraw(false);
        IGNORE = new ArrayList<ArtistData>();
        LAST_FM = new LastfmAPI();
	}
	
	public static String getSexString(int x) {
		if(x == 1) { return "Females"; }
		if(x == 2) { return "Males"; }
		return "All";
	}
	
	//Custom Button colors
	public static void setButtonColors(controlP5.Button btn) {
		btn.setColorCaptionLabel(0);
    	btn.setColorForeground(GLOBAL.colorTabSelected);
    	btn.setColorActive(GLOBAL.colorTabMouseOver);
    	btn.setColorBackground(GLOBAL.colorTabDeselected);
	}
	
	public static void startGradient() {
		gradientOne = !gradientOne;	//Switch gradients
		adjust = 0;
	}
	
	public static int getNextGradientColor() {
		int color = 0;
		
		if(gradientOne)
			color = processing.color(g1_r, g1_g+adjust, g1_b+adjust);
		else
			color = processing.color(g2_r, g2_g+adjust, g2_b+adjust);
		
		adjust += 3;
		
		return color;
	}
	
	//When user clicks on a graph,
	//	Graph sends y position of mouse,
	//		&& Artist # in list
	//The following method then alerts the proper View of the event
	public static void sendEventToView(int yCoord, int index) {
		if(VIEW_COUNT == 1 || yCoord < ViewMidline)
			radioGaGa.View1.handleEvent(index);
		else
			radioGaGa.View2.handleEvent(index);
	}

	//Remove an Artist from the Ignore list via their name
	public static void removeByName(String artistName) {
		for(int x=0; x<IGNORE.size(); ++x) {
			if(artistName.equals(IGNORE.get(x).getName())) {
				IGNORE.remove(x);
				return;
			}
		}
	}
	
	//Find Artist by name in overall list
	public static int findArtist(String artistName) {
		for(int x=0; x<radioGaGa.ArtistList.size(); ++x) {
			if(radioGaGa.ArtistList.get(x).getName().equals(artistName))
				return x;
		}
		
		return -1;
	}
	
	public static void loadDefaultFont() {
		processing.textFont(GLOBAL.fontSegoe);
		processing.smooth();
		processing.textSize(12);
	}
}
//